var util = require("../../../utils/util.js"),
  api = require("../../../utils/api.js"),
  app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    matchmaker_id:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.hideShareMenu();
    this.getUserInfo()
  },
  async getUserInfo(){
    let {matchmaker_id}=await api.default.getUserInfo();
    this.setData({
      matchmaker_id:matchmaker_id?true:false,
  })
},
  readyPdf(e) {
    const {
      flag
    } = e.currentTarget.dataset;
    api.default.config().then((a) => {
      if (a.code == 1) {
        let url = '';
        if (flag == 1) {
          url = app.globalData.baseImgUrl + a.data.agreement;
        } else if (flag == 2) {
          url = app.globalData.baseImgUrl + a.data.contract;
        } else if (flag == 3) {
          url = app.globalData.baseImgUrl + a.data.financial_contract;
        }else if (flag == 4) {
          url = app.globalData.baseImgUrl + a.data.privacy_policy;
        }else if (flag == 5) {
          url = app.globalData.baseImgUrl + a.data.financial_contract_abstract;
        }else if (flag == 6) {
          url = app.globalData.baseImgUrl + a.data.third_party_information;
        }else if (flag == 7) {
          url = app.globalData.baseImgUrl + a.data.personal_information_collection;
        }else if (flag == 8) {
          url = app.globalData.baseImgUrl + a.data.information_specifications;
        }else if (flag == 9) {
          url = app.globalData.baseImgUrl + a.data.bulletin_board;
        }
        console.log('url',url)
        wx.downloadFile({
          url: url,
          success: function (resinfo) {
            console.log("pdf协议文件已下载")
            let path = resinfo.tempFilePath;
            console.log(path, resinfo)
            wx.openDocument({
              filePath: path,
              fileType: 'pdf',
              success: function (rest) {
                console.log(rest);
              },
              fail: function (error) {
                console.log('error',error)
                wx.showToast({
                  icon: 'none',
                  title: '打开文件失败'
                });
              },
            })
          },
          fail: function (err) {
            wx.showToast({
              icon: 'none',
              title: '下载文件失败'
            });
          }
        })
      }
    });
  },
  onSubmit(){
    wx.showModal({
      title: '提示',
      content: '注销账户，平台将删除你在平台所有信息，是否要进行此操作?',
      complete: (res) => {
        if (res.confirm) {
          wx.showLoading();
          api.default.logOff().then(res => {
            wx.hideLoading();
            if (res.code == 1) {
              wx.showToast({
                title: '操作成功！',
                icon: 'success'
              })
              wx.switchTab({
                url: '/pages/index/index',
              })
            }
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})